

clear all
set more off
version 13

local gruppo = 1

log  using  .../A_6_`gruppo'_2_13Sep2020.smcl, replace



use .../left_cens_spell_10sample_10never_type_`gruppo'_conv_2_13Sep2020.dta,clear 
capture drop __000*

*runnare dopo convexity
** make as in wen and gordon, 
gen pred_naer=exp((var_naer/2)+pred_lnnaer)
gen pred_wage_good=exp((var_wage/2)+pred_lnwage)

set more off

foreach y of num 1993/2011 {
      if `y'==1993 {
  
	   tempvar gross gross1 alm0 alm1 xss xkom  xsta name b b1 z dedu k
           gen  `gross' = 0
           gen `gross1' = 0
           gen   `ordinary0' = 0
           gen   `ordinary1' = 0
           gen    `sic' = 0
           gen   `flat' = 0
           gen   `surtax' = 0
	   gen   `z' = pred_wage_good
           gen   `b'= 0
           gen   `b1'= `b'*1
	   gen   `dedu' = 0
	   gen `k'=capital_income
	   // Deductions 
           replace `dedu' = min(27600, max((`z'+`b')*.2,3300))
              
           // Tax base and calculated taxes
           replace `gross' = `z'+`b'  	if year==`y'														     // for business using here net naering b
           replace `gross1' = `z'+`b1'		if year==`y'															 // for business using here imputed labor b1
           replace `ordinary0' = max(`gross' + `k' - `dedu', 0)   	if year==`y'                      // k is capital           
           replace `ordinary1' = max(`ordinary0' - 22200 , 0) if year==`y'

           replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross'>17000) , 0.25*[`gross'-17000]) , 0) 	if year==`y'         // for wages and b business (net_naering)

           replace `flat' = `ordinary1'*.28 if year==`y'															  // for business use net naering, flat tax
           replace `surtax' = max(`gross1'-204000,0)*.095 + max(`gross1'-247000,0)*.042 	if year==`y'               // surtax, use imputed personal for business
                    
           // Total income tax 
           gen tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'  	if year==`y'
 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	  
	  // Deductions 

	  
          replace `gross' = `z'+`b'  	if year==`y'														     // for business using here net naering b
          replace `gross1' = `z'+`b1'		if year==`y'															 // for business using here imputed labor b1
          replace `ordinary0' = max(`gross' + `k' - `dedu', 0)   	if year==`y'                      // k is capital           
          replace `ordinary1' = max(`ordinary0' - 22200 , 0) if year==`y'

          replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross'>17000) , 0.25*[`gross'-17000]) , 0) 	if year==`y'         // for wages and b business (net_naering)

          replace `flat' = `ordinary1'*.28 if year==`y'															  // for business use net naering, flat tax
          replace `surtax' = max(`gross1'-204000,0)*.095 + max(`gross1'-247000,0)*.042 	if year==`y'               // surtax, use imputed personal for business
                    
           // Total income tax 
          gen tax_pred_naer_`y' = `sic' + `flat' + `surtax'  	if year==`y'

	  
      }      
      if `y'==1994 {
  
           replace  `gross' = 0
           replace `gross1' = 0
           replace   `ordinary0' = 0
           replace   `ordinary1' = 0
           replace    `sic' = 0
           replace   `flat' = 0
           replace   `surtax' = 0
	   replace   `z' = pred_wage_good
           replace   `b'= 0
           replace   `b1'= `b'*1
	   replace   `dedu' = 0
	   // Deductions 
           replace `dedu' = min(28100, max((`z'+`b')*.2,3400))
              
           // Tax base and calculated taxes
           replace `gross' = `z'+`b'  	if year==`y'														     // for business using here net naering b
           replace `gross1' = `z'+`b1'		if year==`y'															 // for business using here imputed labor b1
           replace `ordinary0' = max(`gross' + `k' - `dedu', 0)   	if year==`y'                      // k is capital           
           replace `ordinary1' = max(`ordinary0' - 22600 , 0) if year==`y'

           replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross'>17000) , 0.25*[`gross'-17000]) , 0) 	if year==`y'         // for wages and b business (net_naering)

           replace `flat' = `ordinary1'*.28 if year==`y'															  // for business use net naering, flat tax
           replace `surtax' = max(`gross1'-208000,0)*.095 + max(`gross1'-252000,0)*.042 	if year==`y'               // surtax, use imputed personal for business
                    
           // Total income tax 
           gen tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'  	if year==`y'
 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	  
	  // Deductions 
	  
          replace `gross' = `z'+`b'  	if year==`y'														     // for business using here net naering b
          replace `gross1' = `z'+`b1'		if year==`y'															 // for business using here imputed labor b1
          replace `ordinary0' = max(`gross' + `k' - `dedu', 0)   	if year==`y'                      // k is capital           
          replace `ordinary1' = max(`ordinary0' - 22600 , 0) if year==`y'

          replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross'>17000) , 0.25*[`gross'-17000]) , 0) 	if year==`y'         // for wages and b business (net_naering)

          replace `flat' = `ordinary1'*.28 if year==`y'															  // for business use net naering, flat tax
          replace `surtax' = max(`gross1'-208000,0)*.095 + max(`gross1'-252000,0)*.042 	if year==`y'               // surtax, use imputed personal for business
                    
           // Total income tax 
          gen tax_pred_naer_`y' = `sic' + `flat' + `surtax'  	if year==`y'

	  
      }
      
      if `y'==1995 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions 
	replace `dedu' = min(28700, max((`z'+`b')*.2,3500)) 
	    
	// Tax base and calculated taxes
	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu', 0) if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 22600 , 0) if year==`y'

	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0) if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28 if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-212000,0)*.095 + max(`gross1'-239000,0)*.042 if year==`y'                 // surtax, use imputed personal for business
			    
	// Total income tax 
	gen tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'  if year==`y'
	
 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions 
		    
	// Tax base and calculated taxes
	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu', 0) if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 22600 , 0) if year==`y'

	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0) if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28 if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-212000,0)*.095 + max(`gross1'-239000,0)*.042 if year==`y'                 // surtax, use imputed personal for business
			    
	// Total income tax 
	gen tax_pred_naer_`y' = `sic' + `flat' + `surtax'  if year==`y'

	  }
      
      
      if `y'==1996 {
  
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions 

	replace `dedu' = min(29800, max((`z'+`b')*.2,3600)) if year==`y'
			 
	// Tax base and calculated taxes
	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 23300 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-220500,0)*.095 + max(`gross1'-248500,0)*.042  if year==`y'                 // surtax, use imputed personal for business

			     
	// Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions 

			 
	// Tax base and calculated taxes
	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 23300 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-220500,0)*.095 + max(`gross1'-248500,0)*.042  if year==`y'                 // surtax, use imputed personal for business

			     
	// Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==1997 {
  
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions 
	replace `dedu' = min(31300, max((`z'+`b')*.2,3700)) if year==`y'
			   
	// Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 24100 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-233000,0)*.095 + max(`gross1'-262500,0)*.042  if year==`y'                 // surtax, use imputed personal for business


	// Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions 
			   
	// Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 24100 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-233000,0)*.095 + max(`gross1'-262500,0)*.042  if year==`y'                 // surtax, use imputed personal for business


	// Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  
      }
      
      if `y'==1998 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions
	replace `dedu' = min(32600, max((`z'+`b')*.2,3700)) if year==`y'
	 
			   
	// Tax base and calculated taxes


	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 25000 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-248000,0)*.095 + max(`gross1'-272000,0)*.042  if year==`y'                 // surtax, use imputed personal for business


	// Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'
			    
			    

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions
	replace `dedu' = 0 if year==`y'
	 
			   
	// Tax base and calculated taxes


	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 25000 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-248000,0)*.095 + max(`gross1'-272000,0)*.042  if year==`y'                 // surtax, use imputed personal for business


	// Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'
			    
			    

	  }
      
      
      if `y'==1999 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions 
	replace `dedu' = min(34900, max((`z'+`b')*.21,3900)) if year==`y'

			   
	// Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 26300 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-269100,0)*.135  if year==`y'                 // surtax, use imputed personal for business

			    
	// Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'
			    

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	// Deductions 

			   
	// Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 26300 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>17000) , 0.25*[`gross1'-17000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-269100,0)*.135  if year==`y'                 // surtax, use imputed personal for business

			    
	// Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'
			    

	  
      }
      
      if `y'==2000 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(36600, max((`z'+`b')*.21,30600)) if year==`y'
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 27700 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>22200) , 0.25*[`gross1'-22200]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-277800,0)*.135 + max(`gross1'-762700,0)*.06  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'


 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 27700 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>22200) , 0.25*[`gross1'-22200]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-277800,0)*.135 + max(`gross1'-762700,0)*.06  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'


	  
      }
      
      if `y'==2001 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	replace `dedu' = min(40300, max((`z'+`b')*.21,31800)) if year==`y'

			 
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 28800 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>22200) , 0.25*[`gross1'-22200]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-289000,0)*.135 + max(`gross1'-793200,0)*.06  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0

			 
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 28800 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>22200) , 0.25*[`gross1'-22200]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-289000,0)*.135 + max(`gross1'-793200,0)*.06  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2002 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(43000, max((`z'+`b')*.21,31800)) if year==`y'

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 30100 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>23000) , 0.25*[`gross1'-23000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-320000,0)*.135 + max(`gross1'-830000,0)*.06  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 30100 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>23000) , 0.25*[`gross1'-23000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-320000,0)*.135 + max(`gross1'-830000,0)*.06  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2003 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(45700, max((`z'+`b')*.21,31800)) if year==`y'

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 31600 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>23000) , 0.25*[`gross1'-23000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-340700,0)*.135 + max(`gross1'-872000,0)*.06  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 31600 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>23000) , 0.25*[`gross1'-23000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-340700,0)*.135 + max(`gross1'-872000,0)*.06  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2004 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good          
	  replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(45700, max((`z'+`b')*.24,31800)) if year==`y'
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 32900 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>23000) , 0.25*[`gross1'-23000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-354300,0)*.135 + max(`gross1'-906900,0)*.06  if year==`y'                 // surtax, use imputed personal for business

			    
	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 32900 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>23000) , 0.25*[`gross1'-23000]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-354300,0)*.135 + max(`gross1'-906900,0)*.06  if year==`y'                 // surtax, use imputed personal for business

			    
	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2005 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good          
	  replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(57400, max((`z'+`b')*.24,31800)) if year==`y'

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 34200 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>29600) , 0.25*[`gross1'-29600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-381000,0)*.12 + max(`gross1'-800000,0)*.035  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 34200 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>29600) , 0.25*[`gross1'-29600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-381000,0)*.12 + max(`gross1'-800000,0)*.035  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2006 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good          
	  replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	replace `dedu' = min(61100, max((`z'+`b')*.24,31800)) if year==`y'

			  
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 35400 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>29600) , 0.25*[`gross1'-29600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-394000,0)*.09 + max(`gross1'-750000,0)*.03  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0

			  
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 35400 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>29600) , 0.25*[`gross1'-29600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-394000,0)*.09 + max(`gross1'-750000,0)*.03  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2007 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
	  replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions
	replace `dedu' = min(63800, max((`z'+`b')*.36,31800)) if year==`y'
	 
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 37000 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.2845  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-400000,0)*.09 + max(`gross1'-650000,0)*.03  if year==`y'                 // surtax, use imputed personal for business


	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions
	 
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 37000 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.107*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.2845  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-400000,0)*.09 + max(`gross1'-650000,0)*.03  if year==`y'                 // surtax, use imputed personal for business


	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2008 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good          
	  replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(67000, max((`z'+`b')*.36,31800)) if year==`y'

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 38850 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.11*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-420000,0)*.09 + max(`gross1'-682500,0)*.03  if year==`y'                 // surtax, use imputed personal for business


	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 38850 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.11*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-420000,0)*.09 + max(`gross1'-682500,0)*.03  if year==`y'                 // surtax, use imputed personal for business


	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2009 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good          
	  replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(70350, max((`z'+`b')*.36,31800)) if year==`y'

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 40800 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.11*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-441000,0)*.09 + max(`gross1'-716600,0)*.03  if year==`y'                 // surtax, use imputed personal for business

			 
	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 

			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 40800 , 0)  if year==`y'


	replace `sic' = max(min([.078*`z'+.11*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-441000,0)*.09 + max(`gross1'-716600,0)*.03  if year==`y'                 // surtax, use imputed personal for business

			 
	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2010 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good          
	  replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(72800, max((`z'+`b')*.36,31800)) if year==`y'
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 42210 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.11*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-456400,0)*.09 + max(`gross1'-741700,0)*.03  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 42210 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.11*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-456400,0)*.09 + max(`gross1'-741700,0)*.03  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      if `y'==2011 {
 
          replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = pred_wage_good
          replace   `b'= 0
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
	replace `dedu' = min(75150, max((`z'+`b')*.36,31800)) if year==`y'
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital           
	replace `ordinary1' = max(`ordinary0' - 43600 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.11*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-471200,0)*.09 + max(`gross1'-765800,0)*.03  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_wage_good_`y' = `sic' + `flat' + `surtax'   if year==`y'

 
	  replace  `gross' = 0
          replace `gross1' = 0
          replace   `ordinary0' = 0
          replace   `ordinary1' = 0
          replace    `sic' = 0
          replace   `flat' = 0
          replace   `surtax' = 0
	  replace   `z' = 0
          replace   `b'= pred_naer
          replace   `b1'= `b'*1
	  replace   `dedu' = 0
	*-* Deductions 
			    
	*-* Tax base and calculated taxes

	replace `gross' = `z'+`b'  															     // for business using here net naering b
	replace `gross1' = `z'+`b1'																 // for business using here imputed labor b1
	replace `ordinary0' = max(`gross' + `k' - `dedu' , 0)  if year==`y'                         // k is capital       
	replace `ordinary1' = max(`ordinary0' - 43600 , 0)  if year==`y'

	replace `sic' = max(min([.078*`z'+.11*`b1']*(`gross1'>39600) , 0.25*[`gross1'-39600]) , 0)  if year==`y'         // for wages and b business (net_naering)
	replace `flat' = `ordinary1'*.28  if year==`y'															  // for business use net naering, flat tax
	replace `surtax' = max(`gross1'-471200,0)*.09 + max(`gross1'-765800,0)*.03  if year==`y'                 // surtax, use imputed personal for business

	*-* Total income tax 
	gen  tax_pred_naer_`y' = `sic' + `flat' + `surtax'   if year==`y'

	  }
      
      
      
   }


gen tax_wage=.
gen tax_nae=.
foreach y of num 1993/2011 {
  replace tax_wage = tax_pred_wage_good_`y' if year==`y' 
  replace tax_nae = tax_pred_naer_`y' if year==`y'
  drop tax_pred_naer_`y'
  }
  
  
 

gen netwage= pred_wage_good-tax_wage
replace netwage= pred_wage_good-tax_wage+capital_income if (capital_income>0)
gen netnae= pred_naer-tax_nae
replace netnae= pred_naer-tax_nae +capital_income if (capital_income>0)
 
gen netincdiff=ln((netnae)/(netwage)) 
cap drop __000*  
save  .../left_cens_spell_10sample_10never_type_`gruppo'_hmle_2_13Sep2020.dta, replace
log close 
